﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Expo.Training.DataAccess.Activity;

public partial class BM_Course_RegistrationXB : Pagebase
{
    public Guid activityId;

    protected void Page_Load(object sender, EventArgs e)
    {
        activityId = GetGuidValue("id");

        if(!IsPostBack){
            this.ltlTitle.Text = ActivityModule.GetActivity(activityId).ActivityTitle;
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string _checkCode = CheckCode.Text.Trim();

        if (!_checkCode.Equals(Session["Vnumber"].ToString().ToLower()))
        {
            AddEndScript("fail", "alert('验证码不正确，请重新输入！');");
            return;
        }

        string _strRealName;
        int _intAge;
        int _intSex;
        string _strHomeAddress;
        string _strContactAddress;
        string _strMobile;
        string _strBeginDate;
        string _strEndDate;
        string _strRequirement;
        int _intCount;

        _strRealName = this.txtRealName.Value.Trim();
        _intAge = int.Parse(this.txtAge.Value.Trim());
        _intSex = this.radioMale.Checked ? 1 : 0;
        _strHomeAddress = this.txtHomeAddress.Value.Trim();
        _strContactAddress = this.txtContactAddress.Value.Trim();
        _strMobile = this.txtMobile.Value.Trim();
        _strBeginDate = this.txtBeginDate.Value;
        _strEndDate = this.txtEndDate.Value;
        _strRequirement = this.txtRequirement.Value.Trim();
        _intCount = int.Parse(this.txtCount.Value.Trim());

        Guid _activityId = GetGuidValue("id");

        ActivityRegistrationEntity _model = new ActivityRegistrationEntity();
        _model.ActivityID = _activityId;
        _model.MemberID = this.MemberID;
        _model.RealName = _strRealName;
        _model.Sex = _intSex;
        _model.Age = _intAge;
        _model.RegNumber = _intCount;
        _model.FamilyAddress = _strHomeAddress;
        _model.ContactAddress = _strContactAddress;
        _model.Mobile = _strMobile;
        _model.BeginDate = DateTime.Parse(_strBeginDate);
        _model.EndDate = DateTime.Parse(_strEndDate);
        _model.Requirement = _strRequirement;
        _model.Intention = string.Empty;
        _model.AddTime = DateTime.Now;
        _model.Comments = string.Empty;
        _model.Status = 1;

        if (ActivityModule.AddRegistration(_model))
        {
            AddEndScript("succes", "alert('报名成功！');location.href='/portal/BM/Default.aspx'");
        }
        else
        {
            AddEndScript("error", "alert('报名失败，请重试！');location.href='RegistrationXB.aspx?id=" + _activityId + "'");
        }
    }
}
